home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 11859 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.6 KB

  1. Path: keats.ugrad.cs.ubc.ca!not-for-mail
  2. From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Is there a problem using memset on a malloc'd memory in HP-C
  5. Date: 26 Mar 1996 16:06:29 -0800
  6. Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
  7. Message-ID: <4ja0q5INN8a6@keats.ugrad.cs.ubc.ca>
  8. References: <31a7cc$10b20.32c@NEWS>
  9. NNTP-Posting-Host: keats.ugrad.cs.ubc.ca
  10.  
  11. In article <31a7cc$10b20.32c@NEWS>,
  12. Jonathan Julian <jul395@prb.mhs.compuserve.com> wrote:
  13.  >I have searched your FAQ and found no reference to this problem.
  14.  >
  15.  >I am having trouble doing a malloc on memory that I allocated via
  16.  >malloc.  I malloc'd the memory, memset it  and immediately look at it
  17.  >and it is garbage.  I have changed my mallocs to callocs, but later in
  18.  >my code I realloc.  Since realloc does not initialize and I
  19.  >distrusting of memset I have written a loop to initialize my memory.
  20.  
  21. Unfortunately, without seeing the source code demonstrating your use of
  22. malloc() and memset(), there is little that can be done in the way of help.
  23.  
  24.  >The structure that I am trying to initialize is an array of pointers
  25.  >to pointers that I would initially like to be NULL.  I am on HP
  26.  >a.09.07  using HP-C
  27.  
  28. Unfortunately, if you expect a block of zero bits to represent null pointers,
  29. you are making a machine-specific assumption. The null pointer is not required
  30. by the C standard to have a zero-bit representation, to reflect the reality
  31. that on some machines the best represetnation for a null pointer is something
  32. other than a word of zero bits.
  33.  
  34. If you want to be strictly conforming, you should intitialize each pointer by
  35. explicit assignment.
  36. -- 
  37.  
  38.